<template>
  <!-- 个人中心消息详情 -->
  <div class="Box" id="message">
    <div v-if="!isShow">
      <div class="TaBbox">
        <radio_group01
          :radio_values="['未读', '已读', '全部']"
          v-model="dateRank"
        />
        <button v-if="type == 1 || type == 0" @click="allDetails()">
          全部标识已读
        </button>
        <button v-else class="whole">全部标识已读</button>
      </div>
      <!-- 内容 -->
      <div class="content" v-if="NewsList && !loading">
        <div class="content-box">
          <ul>
            <li v-for="(item, index) in NewsList" :key="index">
              <div class="left">
                <!-- <img
                  src="../../../assets/li/unread.png"
                  alt
                  v-if="item.isRead == 0"
                />-->
                <p :class="item.isRead ? 'isReadActive' : ''" class="pOne">
                  {{ item.title }}
                </p>
                <p class="pTwo">{{ item.msg }}</p>
              </div>
              <div class="right">
                <p class="pOne" @click="Details(item.id)">查看详情</p>
                <p :class="item.isRead ? 'isReadActive' : ''" class="pTwo">
                  {{ item.createTime }}
                </p>
              </div>
            </li>
          </ul>
        </div>
      </div>
      <!-- 加载框 -->
      <div
        v-loading="loading"
        v-if="loading"
        class="loading"
        element-loading-text="拼命加载中..."
        element-loading-spinner="el-icon-loading"
      ></div>
      <!-- 分页 -->
      <div class="pageBox" v-if="!loading && NewsList">
        <el-pagination
          background
          layout="prev, pager, next,jumper"
          :page-size="pageSize"
          :current-page="pageIndex"
          :total="count"
          @current-change="getNewsList"
          :hide-on-single-page="true"
        ></el-pagination>
      </div>
      <div class="empty" v-show="!loading && NewsList.length == 0">
        <img src="@/assets/liu/zw.png" />
        <p>目前没有可以查看的数据哟~</p>
      </div>
    </div>
    <!-- 详情 -->
    <div class="msg_details" v-if="isShow">
      <p class="top"><span @click="goBack">消息列表</span>>消息详情</p>
      <div class="msg_box">
        <p class="msg_title">{{ details.title }}</p>
        <p class="time">{{ details.createTime }}</p>
      </div>
      <div class="certer_box">
        {{ details.msg }}
        <span v-if="isTo"
          >, 点击<span class="color" @click="$router.push('/talent_main/buy')"
            >立即续费</span
          ></span
        >
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {},
  data() {
    return {
      pageSize: 10, // 每页条数
      pageIndex: 1, // 页码
      count: null, // 总条数
      loading: false, // 加载动画
      NewsList: [], // 消息列表
      dateRank: "未读", //未读
      type: "1",
      isShow: false,
      details: "",
      isTo: false
    };
  },

  watch: {
    dateRank(value) {
      switch (value) {
        case "未读":
          this.type = 1;
          break;
        case "已读":
          this.type = 2;
          break;
        case "全部":
          this.type = 0;
          break;
      }
      this.NewsList = [];
      this.pageIndex = 1;
      this.getNewsList();
    }
  },
  created() {
    this.getNewsList();
  },
  mounted() {},
  methods: {
    // 获取全部消息列表
    getNewsList(page) {
      if (page) {
        this.pageIndex = page;
      }
      this.NewsList = [];
      this.loading = true;
      this.$axios({
        method: "get",
        url: "/api/customer/GetMsg",
        params: {
          type: this.type, //0 全部 1未读 2已读
          page: this.pageIndex,
          size: this.pageSize
        }
      })
        .then(res => {
          this.loading = false;
          if (res.data.code == 0) {
            this.NewsList = res.data.data;
            this.count = res.data.count;
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    // 查看详情
    Details(id) {
      this.$axios({
        method: "get",
        url: "/api/customer/getMsgDetail",
        params: {
          id: id
        }
      }).then(res => {
        if (res.data.code == 0) {
          this.details = res.data.data;
          this.isTo = this.details.msg.indexOf("购买续费") != -1;
        }
      });
      this.isShow = !this.isShow;
      this.backTop();
    },
    allDetails() {
      if (this.dateRank == "已读") {
        return;
      } else {
        this.$axios.post("/api/customer/readAllMsg").then(res => {
          if (res.data.code == 0) {
            this.getNewsList();
          }
        });
        if (document.getElementsByClassName("el-message").length === 0) {
          this.getNewsList();
          this.$message({
            message: "操作成功！",
            type: "success",
            duration: 2000
          });
        }
      }
    },
    goBack() {
      this.getNewsList();
      this.isShow = !this.isShow;
    },
    backTop() {
      document.body.scrollTop = document.documentElement.scrollTop = 0;
    }
  },
  computed: {}
};
</script>

<style scoped lang="less">
.Box {
  padding: 20px;
}
.TaBbox {
  margin-bottom: 10px;
  width: 100%;
  height: 32px;
  display: flex;
  justify-content: space-between;
  box-sizing: border-box;
  button {
    float: right;
    width: 110px;
    height: 32px;
    border-radius: 4px;
    border: solid 1px #fd7f2c;
    color: #fd7f2c;
    margin-right: 10px;
    font-size: 14px;
  }
  .whole {
    border: solid 1px #b6b6b6;
    background-color: #fff;
    color: #b6b6b6;
  }
}
.content {
  width: 100%;
  margin-top: 6px;
  .content-box {
    width: 100%;
    ul {
      width: 100%;
      li {
        position: relative;
        display: flex;
        justify-content: space-between;
        width: 100%;
        height: 79px;
        border-bottom: 1px solid #e5e5e5;
        // border: 1px solid #e5e5e5;
        padding-left: 16px;
        padding-right: 12px;
        box-sizing: border-box;
        .left {
          font-size: 14px;
          .pOne {
            color: #222222;
            margin-top: 20px;
            font-weight: 600;
          }
          .pOne1 {
            color: #222222;
            margin-top: 20px;
            font-weight: 600;
          }
          .pTwo {
            margin-top: 8px;
            color: #888888;
          }
          img {
            width: 10px;
            height: 10px;
            position: absolute;
            left: 2px;
            top: 25px;
          }
        }
        .right {
          font-size: 14px;
          text-align: center;
          .pOne {
            margin-top: 20px;
            color: #fd7f2c;

            &:hover {
              cursor: pointer;
            }
          }
          .pTwo {
            margin-top: 8px;
            color: #888888;
          }
        }
      }
    }
  }
}
.msg_details {
  .top {
    padding-left: 15px;
    font-size: 14px;
    span:nth-child(1) {
      font-weight: normal;
      color: #fd7f2c;
      cursor: pointer;
    }
    span:nth-child(2) {
      font-weight: normal;
      color: #888888;
    }
  }
  .msg_box {
    padding-left: 15px;
    margin-top: 40px;
    padding-bottom: 18px;
    border-bottom: 1px solid #e5e5e5;
    .msg_title {
      font-size: 22px;
      font-weight: 600;

      color: #222222;
    }
    .time {
      margin-top: 12px;
      font-size: 14px;
      font-weight: normal;
      color: #888888;
    }
  }
  .certer_box {
    padding-top: 30px;
    padding-left: 15px;
    font-size: 14px;
    font-weight: normal;
    color: #222222;
    .color {
      color: #fd7f2c;
      cursor: pointer;
    }
  }
}
.isReadActive {
  color: #aaa !important;
}
</style>
